package com.bwstudio.demo.provider.service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.apache.dubbo.config.annotation.Service;

import com.bwstudio.demo.provider.api.OtherService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class OtherServiceImpl implements OtherService {

	private void sleep() {
		try {
			TimeUnit.SECONDS.sleep(5);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public String doFirst() {
		sleep();
		return "doFirst()";
	}

	@Override
	public String doSecond() {
		sleep();
		return "doSecond()";	
	}

	@Override
	public CompletableFuture<String> doThird() {
		long startTime = System.currentTimeMillis();
		sleep();
		CompletableFuture<String> future = 
				CompletableFuture.completedFuture("doThird()------");
		long endTime = System.currentTimeMillis();
		long useTime = endTime - startTime;
		log.info("doThird()方法执行用时：" + useTime);
		return future;
	}

	@Override
	public CompletableFuture<String> doFourth() {
		long startTime = System.currentTimeMillis();
		sleep();
		CompletableFuture<String> future = 
				CompletableFuture.completedFuture("doFourth()------");
		long endTime = System.currentTimeMillis();
		long useTime = endTime - startTime;
		log.info("doFourth()方法执行用时：" + useTime);
		return future;
	}

}
